
#购物系统业务需求V1.0


money = 5000
commodity = ["电视", "空调", "洗衣机", "茶壶"]
commodity_price = [("电视", 2000), ("空调", 1500), ("洗衣机", 1000), ("茶壶", 50)]
shopping_Car = []


def goods():
    print("欢迎购物")
    print("目前商城有以下商品")
    for index, (name, price) in enumerate(commodity_price):
        print(f"{index} {name} - {price} 元")


def shopping():
    global money
    while True:
        goods()
        i = input("请选择您要购买的商品，如不想购物可输入Q或q退出")
        if i.lower() == "q":
            break
        found = False
        for name, price in commodity_price:
            if i == name:
                if money >= price:
                    shopping_Car.append((name, price))
                    money -= price
                    print(f"恭喜，购买成功！您的卡余额还剩{money}")
                else:
                    print("穷鬼，钱不够！请到其他超市购买！")
                found = True
                break
        if not found:
            print("没有这个商品，别瞎弄！")
            break


def receipt():
    print("---购物小条---")
    sum = 0
    for name, price in shopping_Car:
        sum += price
        print(f"{name}: {price}")
    print("共消费：", sum)
    print(f"余额:{money}元")


shopping()
receipt()












#购物系统业务需求V2.0
import random
import time


formatted_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print("格式化后的本地时间:", formatted_time)

money = 5000
commodity = ["电视", "空调", "洗衣机", "茶壶","电脑"]
commodity_price = [("电视", 2000), ("空调", 1500), ("洗衣机", 1000), ("茶壶", 50),("电脑",4000)]
shopping_Car = []
commodity_pre = [("电视",0.8),("电视",0.9),("空调",0.8),("空调",0.9),("洗衣机",0.8),("洗衣机",0.9),("茶壶",0.8),("茶壶",0.9),("电脑",0.8),("电脑",0.9)]
name1 = ""
count = 0
def goods():
    print("欢迎购物")
    print("目前商城有以下商品")
    for index, (name, price) in enumerate(commodity_price):
        print(f"{index} {name} - {price} 元")

def re_goods(x):
    global money,count,shopping_Car
    found = False
    for name,price in shopping_Car:
        if x == name:
            shopping_Car.remove((name,price))
            money += price
            count -= 1
            print("退货成功")
            found = True
            break
    if not found:
        print("购物车内无该商品")



def shopping():
    global money, name1,count
    price1 = 0
    while True:
        goods()
        if price1 == 0:
            print(commodity_pre)
            print("将从以上优惠卷中随机抽取一张")
            name1, price1 = random.choice(commodity_pre)
            print(f"恭喜您抽到{name1}:{price1 * 10}折卷")
        i = input("请选择您要购买的商品，如不想购物可输入Q或q退出")
        if i.lower() == "q":
            break
        found = False
        for name, price in commodity_price:
            if i == name:
                if i == name1:
                    price *= price1
                else:
                    price = price

                if money >= price:
                    shopping_Car.append((name, price))
                    money -= price
                    count = count + 1
                    print(f"恭喜，购买成功！您的卡余额还剩{money}")
                    print("请问是否需要退货？需要输入T或t，不需要输入任意字符")
                    r = input()
                    if r.lower() == "t":
                        rg = input("输入需要退货的商品")
                        re_goods(rg)

                else:
                    print("穷鬼，钱不够！请到其他超市购买！")

                found = True
                break

        if not found:
            print("没有这个商品，别瞎弄！")
            break




def receipt():
    print("---购物小条---")
    print("购物时间:",time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

    sum = 0
    for name, price in shopping_Car:
        sum += price
        print(f"{name}: {price}")
    print("购物数量：",count)
    print(f"卡余额:{money}元")
    print("共消费：", sum)



shopping()
receipt()

